package com.cfs.svcimpl.bz;

import java.util.List;

import com.cfs.dao.bz.ReportDao;
import com.cfs.po.bz.Report;
import com.cfs.svc.bz.ReportService;
import com.cfs.vo.Condition;
import com.cfs.vo.Pager;
import com.cfs.vo.Res;


public class ReportServiceImpl implements ReportService{

	private ReportDao dao;
		
	public ReportDao getDao() {
		return dao;
	}

	public void setDao(ReportDao dao) {
		this.dao = dao;
	}

	public List<Report> listDid(String did) {
		return dao.listDid(did);
	}

	public List<Report> list(Condition c) {
		return dao.list(c);
	}

	@Override
	public Res<Report> listP(Condition c) {
		Res<Report> res = new Res<Report>();
		try{
			Pager p = c.getP() == null ? new Pager() : c.getP();
			p.resetTotalR(dao.queryRows(c));
			List<Report> list = dao.list(c);

			res.setP(p);
			res.setList(list);

		}catch(Exception e){
			res.setCode(-1);
			res.setMsg(e.getLocalizedMessage());
			e.printStackTrace();
		}
		
		return res;
	}

	public Report get(Long id) {
		return dao.get(id);
	}

	public Long add(Report r) {
		Long n = dao.insert(r);
		System.out.println("RETURN Report NUM: " + n + " ID:" + r.getId() );
		return r.getId();
	}

	public int deleteById(Long id) {
		return dao.delete(id);
	}

	public Long update(Report r) {
		return dao.update(r);
	}

	public Long valuation(Report r) {		
		return dao.valuation(r);
	}

}
